package mid;

import java.util.ArrayList;
import java.util.List;

public class a1790_仅执行一次字符串交换能否使两个字符串相等 {
    public boolean areAlmostEqual(String s1, String s2) {
        if (s1.length()!=s2.length()){
            return false;
        }
        if (s1.equals(s2)){
            return true;
        }
        List<Character> list1 = new ArrayList<>(), list2=new ArrayList<>();
        for (int i = 0; i <s1.length() ; i++) {
            if(s1.charAt(i)!=s2.charAt(i)){
                list1.add(s1.charAt(i));
                list2.add(s2.charAt(i));
            }
        }
        return list1.size()==0||list1.size()==2&&list1.get(0)==list2.get(1)&&list1.get(1)==list2.get(0);
    }
}
